<?php
/**
 * Admin - View Associa Locale a Contatto - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    16-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
    function selectable(){
	$('a[id^="link-partner"]').click(function(){
            var id = $(this).attr('id');
            $.ajax({
                url: '/admin/ajax/add/partnertocontact/id/'+id.substr(13,id.length),
                context: document.body
                }).success(function(data) { 
                    $('#selected_partners').append(data);
                    unselectable();
                }).error(function(obj,text,error) {
                   //show error
                   $('li#errorLi').show();
                   $('li#errorLi p#errorMsg').html(obj.responseText);
                });
            })
    };

    function unselectable(){
        $('a[id^="unlink-partner"]').click(function(){
            $(this).parents('tr.unselectable').remove();
	})
    };
     
    $(document).ready(function()
    {
        var paginator =	$('#partners').pagination({
	    'targetUrl' : '/admin/ajax/list/partnersmini',
	    'orderField' : 'partner_name',
	    'orderDir' : 'asc'
            },selectable // CallBack
        );

	$("#new").fancybox({
	    'type' : 'ajax',
	    'showCloseButton' : false
	});
        
	// Lancio unselectable per i contatti eventualmente già presenti...
	unselectable();
    });

    //]]>
</script>
<div class="info">
    <h2>Associa Contatto</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>
<form id="form-invia" method="post" action="/admin/contatti/associapartner/id/<?php echo $this->contact_id ?>">
    <ul id="paging-live">
        <li class="paging-context ">
        <table class="pgStyle1 circle2" cellspacing="0">
            <tr>
                <td class="c">
                    <var>1</var>
                </td>
                <td class="t">
                    <b id="pagecircle1"><a href="/admin/contatti/info/id/<?php echo $this->contact_id ?>">Dettagli Contatto</a></b>
                </td>
                <td class="c">
                    <var>2</var>
                </td>
                <td class="t">
                    <b id="pagecircle2"><a href="/admin/contatti/associa/id/<?php echo $this->contact_id ?>">Associa Contatto</a></b>
                </td>
                <td class="c selected">
                    <var>2</var>
                </td>
                <td class="t selected">
                    <b id="pagecircle2">Associa a Partner</b>
                </td>
            </tr>
        </table>
        </li>
    </ul>
    <div id="content">
        <div id="summary" class="contact">
            <div class="head contact">
                <h2>Riepilogo Contatto:</h2>
            </div>
            <div class="body">
                <table cellspacing="0" class="table">
                    <tbody>
                        <tr>
                            <th>Nome:</th>
                            <td>
                                <strong>
                                <?php echo $this->data['contact_firstname'] ?>
                                <?php echo $this->data['contact_lastname'] ?>
                                </strong>
                            </td>
                        </tr>
                        <tr>
                            <th>Email Principale:</th>
                            <td>
                                <strong>
                                <?php echo $this->data['contact_email'] ?>
                                </strong>
                            </td>
                        </tr>
                        <tr>
                            <th>Telefono Principale:</th>
                            <td>
                                <strong>
                                <?php echo $this->data['contact_phone'] ?>    
                                </strong>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>        
        <ul>
            <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
                <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
                <p id="errorMsg">
                    <?php var_dump( $this->errorMsg ) ?>
                </p>
            </li>	
        </ul>

        <div id="detailTableLeft">
            <ul>
                <li id="fo2li107" class="likert col2">
                    <table cellspacing="0">
                        <caption id="title107">
                            Clicca per Selezionare:
                        </caption>                                                
                        <thead>
                            <tr>
                                <td colspan="5" class="pagination">
                                    <div class="paginator">
                                        <span class="prev">
                                            <a href="javascript: void(0);">&nbsp;</a>
                                        </span>
                                        <span class="loader">Sto caricando...</span>
                                        <span class="next">
                                            <a href="javascript: void(0);">&nbsp;</a>
                                        </span>
                                    </div>
                                </td>
                            </tr>		    
                            <tr>
                                <th class="sortable default {ref: 'partner_name'}">Nome</th>
                                <td colspan="3">&nbsp;</td>
                            </tr>
                        </thead>
                        <tbody id="partners">
                            <!-- Questo contenuto verrà rimpiazzato dalla paginazione-->

                        </tbody>
                    </table>
                </li>
            </ul>
        </div>	
        <div id="detailTableRight">
            <ul>
                <li id="fo2li107" class="likert col2">
                    <table cellspacing="0">
                        <caption id="title107">
                            Clicca per Deselezionare:
                        </caption>                        
                        <thead>
                            <tr>
                                <td colspan="4">&nbsp;</td>
                            </tr>		    
                        </thead>
                        <tbody id="selected_partners">
                            <!-- Questo contenuto verrà rimpiazzato dalla paginazione-->
                            <?php $i = 0;
                                if( is_array( $this->data['contact_locations'] ) ):
                                foreach( $this->data['contact_locations'] AS $location ) : 
                                ?>
                                <tr class="unselectable" id="location_<?php echo $location['location_id'] ?>">
                                    <th>
                                        <span><?php echo $location['location_name'] ?></span>
                                    </th>
                                    <td title="<?php echo $location['location_city'] ?>">
                                        <span><?php echo $location['location_city'] ?></span>
                                        <span>(<?php echo $location['province_short_name'] ?>)</span>
                                    </td>
                                    <td>
                                        <ul>
                                            <li class="complex">
                                                <span class="left">
                                                    <label>Ruolo:</label>
                                                    <select class="field select addr" name="locations[<?php echo $location['location_id'] ?>][]" id="location_<?php echo $location['location_id'] ?>">
                                                    <?php foreach( $this->contact_roles AS $k => $role ) : ?>
                                                        <option value="<?php echo  $k ?>" <?php echo ( $location['fab_contacts_role'] == $k ) ? 'selected="selected"' : ''?>><?php echo  $role ?></option>
                                                    <?php endforeach; ?>
                                                    </select>
                                                </span>
                                            </li>
                                        </ul>
                                    </td>
                                    <td title="Operazioni">
                                        <span class="actions">
                                            <a class="del" id="unlink-location-<?php echo $location['location_id']?>" href="#">
                                                &nbsp;
                                            </a>
                                        </span>
                                    </td>
                                </tr>
                                <?php
                                $i++;
                                endforeach;
                            endif;?>                              
                        </tbody>
                    </table>		
                    <input type="hidden" name="conferma" id="conferma" value="conferma" />
                </li>
            </ul>
        </div>
        <br style="clear: both" />
        <ul>
            <li class="section">
                <h3>Oppure:</h3>
                <ul>
                    <li class="addnew">
                        <a id="new" class="button" href="/admin/ajax/form/newartist">
                            <img src="/images/admin/add-new.png" />Aggiungi Nuovo Artista (Veloce)
                        </a>
                    </li>
                </ul>
            </li>
        </ul>    
    </div>
    <div id="formButtons">
        <button id="salva" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Continua
        </button>
        <a id="annulla" name="annulla" value="annulla" class="button negative" href="#">
            <img src="/images/admin/cross.png" alt="" />Annulla
        </a>
    </div>
</form>
